package com.mhh.selary.backend.controller.user;

import com.mhh.sdk.beans.dto.PageResultDTO;
import com.mhh.selary.backend.api.user.ISelaryUserAccountService;
import com.mhh.selary.backend.dto.IdDTO;
import com.mhh.selary.backend.dto.user.UserChangePwdDTO;
import com.mhh.selary.backend.dto.user.UserInfoDTO;
import com.mhh.selary.backend.dto.user.UserInitPwdDTO;
import com.mhh.selary.backend.dto.user.UserListDTO;
import com.mhh.selary.backend.dto.user.UserQueryDTO;
import com.mhh.selary.backend.dto.user.UserResetPwdDTO;
import com.mhh.selary.backend.dto.user.UserSaveDTO;
import com.mhh.selary.backend.dto.user.UserSwitchDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author mhh
 * @date 2020-11-23 14:08:49
 */
@Slf4j
@RestController
@Api(tags = "用户模块")
@RequestMapping("/user")
public class UserController {

    @Autowired
    private ISelaryUserAccountService userAccountService;

    @PostMapping("list")
    @ApiOperation("账号列表")
    public PageResultDTO<UserListDTO> list(@RequestBody UserQueryDTO dto) {
        return userAccountService.list(dto);
    }

    @PostMapping("detail")
    @ApiOperation("账号详情")
    public UserInfoDTO detail(@RequestBody IdDTO dto) {
        return userAccountService.detail(dto);
    }

    @PostMapping("save")
    @ApiOperation("保存账号")
    public void save(@RequestBody UserSaveDTO dto) {
        userAccountService.save(dto);
    }

    @PostMapping("initPwd")
    @ApiOperation("修改初始化密码")
    public void initPwd(@RequestBody UserInitPwdDTO dto) {
        userAccountService.initPwd(dto);
    }

    @PostMapping("changePwd")
    @ApiOperation("修改本人密码")
    public void changePwd(@RequestBody UserChangePwdDTO dto) {
        userAccountService.changePwd(dto);
    }

    @PostMapping("resetPwd")
    @ApiOperation("重置密码")
    public UserResetPwdDTO resetPwd(@RequestBody IdDTO dto) {
        return userAccountService.resetPwd(dto);
    }

    @PostMapping("switchUser")
    @ApiOperation("启用/禁用")
    public void switchUser(@RequestBody UserSwitchDTO dto) {
        userAccountService.switchUser(dto);
    }

    @PostMapping("deleteUser")
    @ApiOperation("删除账号")
    public void deleteUser(@RequestBody IdDTO dto) {
        userAccountService.deleteUser(dto);
    }

}
